/**
 * @param {number[]} nums
 * @return {number}
 */
// 采用的计数（有快慢指针的影子）
var removeDuplicates = function (nums) {
  let len = 1, temp = 1
  for (let i = 1; i < nums.length; i++) {
    if (nums[i] == nums[len - 1]) {
      temp++
      if (temp <= 2) {
        nums[len++] = nums[i]
      }
    } else {
      temp = 1
      nums[len++] = nums[i]
    }
  }
  console.log(nums)
  return len
}
// 快慢指针
var removeDuplicates2 = function (nums) {
  const len = nums.length
  // 数组长度小于等于2，无须操作，直接返回
  if (len <= 2) return len
  let slow = 2, fast = 2
  // 由于数组有序，相同的元素位置必连续
  // 故只需要检查快指针的元素和slow - 2是否相等即可
  while (fast < len) {
    if (nums[fast - 1] != nums[slow - 2]) {
      nums[slow++] = nums[fast - 1]
    }
    fast++
  }
}
removeDuplicates([0, 0, 1, 1, 1, 1, 2, 3, 3])